<template>
	<view class="contaner">
		<view class="content">
			<view class="item">
				<van-row>
					<van-col span="18" style="font-weight: 600;">治疗方法说明</van-col>
					<van-col span="3">
					<view @click="PhoneClick">
						<van-icon color="#02BF88" name="phone-o" size="24" />
					</view>
					</van-col>
					  <van-col span="3">
						<view @click="collectClick">
					  	<van-icon v-if="!collShow"  color="#02BF88" name="like-o" size="24" />
						<van-icon v-if="collShow" color="#02BF88" name="like" size="24" />
					  </view>
					  </van-col>
				</van-row>
				<van-row>
					<van-col>{{pamare.drugs}}</van-col>
				</van-row>
			</view>
			<view class="item3">
				<van-row>
					<van-col span="6" style="font-weight: 600;">综合评价</van-col>
					<van-col span="16"><van-rate readonly  :value="pamare.starLevel" size="18" color="#02BF88" /></van-col>
				</van-row>
			</view>
			<view class="item">
				<van-row>
					<view style="border-bottom: 1px solid #EBEDF0; padding-bottom: 4rpx;">全部评论({{msgAll}})</view>
				</van-row>
				<van-row>
					<view class="l-emiy" v-if="discussArr.length === 0">暂无评价</view>
					<view v-else>
						<scroll-view
							scroll-y="true"
							:show-scrollbar="false"
							:enhanced="true"
							@scrolltolower="loadMore1"
							style="height: calc(10vh);"
						>
							<van-row v-for="item in discussArr" :key="item">
								<van-col span="4">
									<van-image
									v-if="item.imagUrl"
									  round
									  width="70rpx"
									  height="70rpx"
									  :src="item.imagUrl"
									/>
									<van-image
									v-else
									  round
									  width="70rpx"
									  height="70rpx"
									  src="https://img01.yzcdn.cn/vant/cat.jpeg"
									/>
								</van-col>
								  <van-col span="12">
									  <view style="color: #333333; font-size: 28rpx;">
									  	{{$replaceLastStr(item.name)}}
									  </view>
									  <view style="font-size: 28rpx; color: #666666;">
									  	{{item.content}}
									  </view>
								  </van-col>
								  <van-col span="8">
									  <view style="height: 38rpx;"></view>
									  <view><van-rate readonly :value="item.starLevel" size="16" color="#02BF88" /></view>
								  </van-col>
							</van-row>
						</scroll-view>
					</view>
				</van-row>
			</view>
			<text class="alList">评分</text>
			<view class="item">
				<view>
						<van-row>
							<van-rate style="flex: 1;" :value="starLevel" size="18" color="#02BF88" @change="onChange" />
						</van-row>
						<van-row>
							<van-col :span="18">
								<view>
									<van-cell-group>
									  <van-field
									    clearable
									    :value="content"
									    type="textarea"
									    placeholder="写评论…"
									    autosize
									    border="false"
										@change="setPL"
									  />
									</van-cell-group>
								</view>
							</van-col>
							<van-col :span="5" offset="1"><van-button style="position: absolute; bottom: 70rpx;" type="primary" round  size="small" @click="sublist">发布</van-button></van-col>
						</van-row>
				</view>
			</view>
			<view class="item1">
				<view v-if="caseArr.length > 0">
					<van-row v-for="item in caseArr" class="l-row" :key="item.id">
						<van-col span="5">
							<image v-if="item.imagUrl" style="vertical-align:middle;" :src="item.imagUrl" mode=""></image>
							<image v-else src="../../../static/defaultImg.png" mode="" style="vertical-align:middle; opacity: .6;"></image>
						</van-col>
						  <van-col span="19">
							  	<view style="padding-left: 16rpx;">
							  		<view style="font-size: 28rpx;">{{$replaceLastStr(item.name)}}</view>
							  		<view style="color: #999; font-size: 22rpx; height: 40rpx;overflow: hidden;">{{item.cureProcess}}</view>
							  			<view class="cc">
											<view class="exceedHidden" style="line-height: 60rpx; width: 75%;"><text class="exceedHidden">{{$replaceLastStr(item.title)}}</text></view>
							  				<view style="width: 25%;">
							  					<van-button type="primary" round  size="small" @click="setDiscuss(item.id)">查看</van-button>
							  				</view>
							  			</view>
							  	</view>
						  </van-col>
					</van-row>
				</view>
				<view v-else class="noData">
				          <view class="text">暂无案例</view>
				  </view>
			</view>
		</view>
		<van-dialog :show="show" title="详情请联系" message="18682369686" confirm-button-color="#02BF88"  @confirm="show = false">
		</van-dialog>
		<van-toast id='van-toast'/>
	</view>
</template>

<script>
import { getcaseList, addComment, isJudge, addColles, unJudge, getDiscussList } from '@/api/appraising.js'	
import { pubList } from '@/api/case.js'
import { fileById } from '@/api/common.js'
	export default {
		data() {
			return {
				collShow: true,
				show: false,
				parameter: {},
				caseArr: [],
				message: '',
				pamare: {},
				starLevel: 3,
				content: '',
				total: 0,
				discussArr: [],
				pagination: {
					pageSize: 10,
					pageNum: 1
				},
				totals: 0,
				paginations: {
					pageSizes: 3,
					pageNums: 1
				},
				msgAll: 0
			}
		},
		onLoad(data) {
			if (data !== null) {
				console.log(data)
				this.pamare = JSON.parse(data.data)
				uni.setNavigationBarTitle({　　                title: this.pamare.remarks                })
				this.isColle()
				this.plAll()
				this.getFeach()
			}
		},
		methods:{
			isColle() {
				isJudge({methodId: this.pamare.id}).then(res => {
					this.collShow = res.data
				})
			},
			plAll(more) {
				let param = {
					methodId: this.pamare.id,
					...this.pagination
				}
				getDiscussList(param).then(res => {
					const newData = res.data
							this.msgAll = this.total = newData.total
							var arr = newData.rows
							if (more === 'more') {
							if (arr.length > 0) {
								arr.forEach(t => {
									this.discussArr.push(t)
									if (t.headPortrait) {
										fileById({fileId: t.headPortrait}).then(r => {
											this.$set(t, 'imagUrl', r.data.accessUrl)
										})
									}
								})
							} else {
								this.$toast.fail('没有更多评价了');
							}
							} else {
								this.discussArr = arr
								this.discussArr.forEach(t => {
									if (t.headPortrait) {
										fileById({fileId: t.headPortrait}).then(r => {
											this.$set(t, 'imagUrl', r.data.accessUrl)
										})
									}
								})
							}
						})
			},
			getFeach(str){
				let param = {
					methodId: this.pamare.id,
					pageSize: this.paginations.pageSizes,
					pageNum: this.paginations.pageNums
				}
				pubList(param).then(res => {
					var arr = res.data.rows
					this.totals = res.data.total
					if (str === 'more') {
						arr.forEach(t => {
							if(t.imgTheme) {
								fileById({fileId: t.imgTheme}).then(res => {
									t.imagUrl = res.data.accessUrl
									this.caseArr.push(t)
								})
							} else {
								this.caseArr.push(t)
							}
						})
					} else {
						arr.forEach((t, index) => {
							if(t.imgTheme) {
								 fileById({fileId: t.imgTheme}).then(res => {
									this.$set(t, 'imagUrl', res.data.accessUrl)
								})
							}
						})
						this.caseArr = [...arr]
					}
				})
			},
			onReachBottom() {
			      console.log('onReachBottom')
			      if ((this.paginations.pageSizes * this.paginations.pageNums) >= this.totals) {
			        return
			      }
			      this.paginations.pageNums++;
			      this.getFeach('more')
			 },
			loadMore1() {
				console.log('到底了')
				if ((this.pagination.pageSize * this.pagination.pageNum) >= this.total) {
				  return
				}
				this.pagination.pageNum++;
				this.plAll('more')
			},
			collectClick() {
				this.collShow = !this.collShow
				if (this.collShow) {
					addColles({methodId: this.pamare.id, type: 1}).then(res => {
						console.log('ab', res)
						if (res.status === 1) {
							this.$toast.success("收藏成功")
						}
					})
				} else {
					unJudge({methodId: this.pamare.id}).then(res => {
						if (res.status === 1) {
							this.$toast.success("已取消")
						}
					})
				}
			},
			PhoneClick() {
				this.show = true
			},
			setDiscuss(id) {
				// 查看到别的页面
				uni.navigateTo({
					url:`/pages/myCase/detail?id=${id}&isComment=true`
				})
			},
			onChange(event) {
				this.starLevel = event.detail
			},
			setPL(e) {
					this.content = e.detail
			},
			sublist() {
				if (!this.content) {
					return this.$toast.fail('请输入发布内容')
				}
				var pamer = {
					methodId: this.pamare.id,
					content: this.content,
					starLevel: this.starLevel
				}
				addComment(pamer).then(res => {
					if (res.status == 1) {
						this.$toast.success("评价成功")
						this.content = ''
						this.$nextTick(() => {
							this.plAll()
						})
					}
				})
			}
			}
			}
</script>

<style scoped lang="scss">
.contaner {
	     height: 100%;
		background-color: #F8F8F8;
		box-sizing: border-box;
		padding: 24rpx 32rpx 58rpx;
		// overflow: auto;
		.content {
			height: 100%;
			.item1,.item {
				background-color: #FFFFFF;
				position: relative;
				width: 100%;
				border-radius: 16rpx;
				padding: 24rpx 16rpx;
				color: #323233;
				font-size: 32rpx;
				line-height: 44rpx;
				box-sizing: border-box;
				margin-bottom: 24rpx;
				/deep/ .van-cell {
					background-color: #F1F1F1;
				}
				/deep/ .van-row {
					margin-bottom: 22rpx;
				}
			}
			.item1 {
				box-sizing: border-box;
				// overflow: hidden;
				// height: calc(100vh - 650rpx);
				padding: 36rpx 16rpx 0 16rpx;
				z-index: 9;
				/deep/ .van-row {
					margin-bottom: 40rpx;
				}
				image {
					width: 120rpx;
					height: 120rpx;
				}
				.left-ment {
					width: 100%;
					box-sizing: border-box;
					height: 180rpx;
					padding-top: 36rpx;
					padding-bottom: 24rpx;
					border-bottom: 1px solid #EBEDF0;
					.left-ment-top {
						width: 48px;
						height: 17px;
						font-size: 12px;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #333333;
						line-height: 17px;
					}
					.left-ment-middle {
						width: 89px;
						height: 16px;
						font-size: 11px;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
						line-height: 16px;
					}
					.left-ment-footer {
						width: 100%;
						height: 100%;
					}
				}
				.right-list {
					padding-left: 16rpx;
					image {
						width: 60px;
						height: 60px;
						border-radius: 8px;
					}
					/deep/ .van-button--round {
						width: 104rpx; height: 48rpx;
					}
					/deep/ .van-row {
						margin-bottom: 44rpx;
					}
				}
				.border-active {
					border-bottom: 1px solid #02BF88;
				}
			}
			.alList {
				width: 160rpx;
				margin-bottom: 16rpx;
				display: inline-block;
				font-size: 32rpx;
				color: #333333;
				font-weight: 600;
			}
			.avtive {
				color: #333;
				position: relative;
			}
			.avtive::after {
			    content: "";
			    display: block;
			    width: 40px;
			    height: 3px;
				margin-top: 18rpx;
				margin-left: 36rpx;
			    background-color: #02BF88
			  }
		}
		.footer {
			position: fixed;
			padding: 24rpx 32rpx;
			box-sizing: border-box;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 132rpx;
			z-index: 99999999999;
			background-color: #FFFFFF;
			/deep/ .van-button--round {
				opacity: 0.3;
			}
		}
	}
	.contaner::-webkit-scrollbar {
     display: none; /* Chrome Safari */}
.item3 {
	background-color: #FFFFFF;
	position: relative;
	width: 100%;
	border-radius: 16rpx;
	padding: 24rpx 16rpx;
	color: #323233;
	font-size: 32rpx;
	line-height: 44rpx;
	box-sizing: border-box;
	margin-bottom: 24rpx;
}.l-emiy {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: #666666;
	font-size: 32rpx;
}
.item1::-webkit-scrollbar {
			display: none; /* Chrome Safari */
	}
	.cc {
		view {
			float: left;
			overflow: hidden;
			text {
				    display: block;
					font-size: 28rpx;
					color: #000000;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
			}
		}
	}
	.l-emiy {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		color: #666666;
		font-size: 32rpx;
	}
</style>
